package org.wak.character.display
{
	/**
	 * Class to load CharacterDisplay definition from XML. 
	 */	
	public class XMLCharDisplayDefinition implements ICharacterDisplayDefinition
	{
		// the input XML.
		private var mDefXML:XML = null;
		
		// true if is a tiled bitmap based anim.
		private var mIsBmpDisplay:Boolean = true;
		
		// true if the char display is the testing dummy display object
		private var mIsDummy:Boolean = false ;
		
		// Id of the character display. 
		private var mCharDisplayId:String = "" ;
		
		//Asociative array BehaviourId->Animation.
		private var mBehavioursArray:Array = null ;
		
		// Speed when the display is moving on the scene.
		private var mSpeed:Number = 10 ;
		
		private var mFrameDelay:Number = 100 ;
		
		private var mPortraitId:String = "" ;
		
		// perspective enabled in the scene.
		private var mUpdatePerspective:Boolean = true ; 
		
		private var mScale:Number = 1 ;
		
		public function XMLCharDisplayDefinition( pDef:XML, pIsBmpAnim:Boolean, pIsDummy:Boolean = false )
		{
			mIsDummy = pIsDummy;
			mDefXML = pDef ;
			mIsBmpDisplay = pIsBmpAnim ;
			mCharDisplayId = pDef.@id ;
			
			if(pDef.@perspective != "")
				mUpdatePerspective = pDef.@perspective == "false" ? false : true ;
				
			if(pDef.@scale != "")
				mScale = pDef.@scale ;
			
			mBehavioursArray = new Array();
			
			for each( var anim:XML in mDefXML.Animation)
			{
				if(anim[0] != "")
					mBehavioursArray[anim.@behaviour] = new Animation(anim);
				//trace(mBehavioursArray[anim.@behaviour]);
			}
			mSpeed = pDef.Speed ;
			mFrameDelay = pDef.@frameDelay ;
			
			if( mFrameDelay == 0)
				mFrameDelay = 100 ;
			
			mPortraitId = pDef.Portrait ;
		}
		
		public function toString():String
		{
			return " IsBmpDisplay:" + mIsBmpDisplay + " CharDisplayId:" + mCharDisplayId + " behaviours:"+mBehavioursArray.toString()  ;
		}

		public function IsBmpDisplay():Boolean
		{
			return mIsBmpDisplay;
		}
		
		public function IsDummyDisplay():Boolean
		{
			return mIsDummy;
		}
		
		public function GetCharDisplayId():String 
		{
			return mCharDisplayId ;
		}
		
		public function GetAnimBehaviour( pBehaviour:String ):Animation 
		{
			return mBehavioursArray[pBehaviour] as Animation ;
		}
		
		public function GetAnimBehaviours():Array 
		{
			return mBehavioursArray ;
		}
		
		public function GetMoveSpeed():Number
		{
			return mSpeed ;
		}
		
		public function GetFrameDelay():Number 
		{
			return mFrameDelay ;
		}
		
		/**
		 * @inheritDoc 
		 */		
		public function GetPortrait():String 
		{
			return mPortraitId ;
		}
		
		public function get perspectiveEnabled():Boolean
		{
			return mUpdatePerspective ;
		}
		
		public function get scale():Number 
		{
			return mScale ;
		}
		
		
	}
}